home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Complete Linux
/
Complete Linux.iso
/
gnu
/
make_std.tex
< prev
next >
Wrap
Text File
|
1993-07-20
|
20KB
|
523 lines
@comment This file is included by both standards.texi and make.texinfo.
@comment It was broken out of standards.texi on 1/6/93 by roland.
@node Makefile Conventions
@chapter Makefile Conventions
@comment standards.texi does not print an index, but make.texinfo does.
@cindex makefile, conventions for
@cindex conventions for makefiles
@cindex standards for makefiles
This chapter describes conventions for writing the Makefiles for GNU programs.
@menu
* Makefile Basics::
* Utilities in Makefiles::
* Standard Targets::
* Command Variables::
* Directory Variables::
@end menu
@node Makefile Basics
@section General Conventions for Makefiles
Every Makefile should contain this line:
@example
SHELL = /bin/sh
@end example
@noindent
to avoid trouble on systems where the @code{SHELL} variable might be
inherited from the environment. (This is never a problem with GNU
@code{make}.)
Don't assume that @file{.} is in the path for command execution. When
you need to run programs that are a part of your package during the
make, please make sure that it uses @file{./} if the program is built as
part of the make or @file{$(srcdir)/} if the file is an unchanging part
of the source code. Without one of these prefixes, the current search
path is used.
The distinction between @file{./} and @file{$(srcdir)/} is important
when using the @samp{--srcdir} option to @file{configure}. A rule of
the form:
@smallexample
foo.1 : foo.man sedscript
sed -e sedscript foo.man > foo.1
@end smallexample
@noindent
will fail when the current directory is not the source directory,
because @file{foo.man} and @file{sedscript} are not in the current
directory.
When using GNU @code{make}, relying on @samp{VPATH} to find the source
file will work in the case where there is a single dependency file,
since the @file{make} automatic variable @samp{$<} will represent the
source file wherever it is. (Many versions of @code{make} set @samp{$<}
only in implicit rules.) A makefile target like
@smallexample
foo.o : bar.c
$(CC) -I. -I$(srcdir) $(CFLAGS) -c bar.c -o foo.o
@end smallexample
@noindent
should instead be written as
@smallexample
foo.o : bar.c
$(CC) $(CFLAGS) $< -o $@@
@end smallexample
@noindent
in order to allow @samp{VPATH} to work correctly. When the target has
multiple dependencies, using an explicit @samp{$(srcdir)} is the easiest
way to make the rule work well. For example, the target above for
@file{foo.1} is best written as:
@smallexample
foo.1 : foo.man sedscript
sed -s $(srcdir)/sedscript $(srcdir)/foo.man > foo.1
@end smallexample
@node Utilities in Makefiles
@section Utilities in Makefiles
Write the Makefile commands (and any shell scripts, such as
@code{configure}) to run in @code{sh}, not in @code{csh}. Don't use any
special features of @code{ksh} or @code{bash}.
The @code{configure} script and the Makefile rules for building and
installation should not use any utilities directly except these:
@example
cat cmp cp echo egrep expr grep
ln mkdir mv pwd rm rmdir sed test touch
@end example
Stick to the generally supported options for these programs. For
example, don't use @samp{mkdir -p}, convenient as it may be, because
most systems don't support it.
The Makefile rules for building and installation can also use compilers
and related programs, but should do so via @code{make} variables so that the
user can substitute alternatives. Here are some of the programs we
mean:
@example
ar bison cc flex install ld lex
make makeinfo ranlib texi2dvi yacc
@end example
When you use @code{ranlib}, you should test whether it exists, and run
it only if it exists, so that the distribution will work on systems that
don't have @code{ranlib}.
If you use symbolic links, you should implement a fallback for systems
that don't have symbolic links.
It is ok to use other utilities in Makefile portions (or scripts)
intended only for particular systems where you know those utilities to
exist.
@node Standard Targets
@section Standard Targets for Users
All GNU programs should have the following targets in their Makefiles:
@table @samp
@item all
Compile the entire program. This should be the default target. This
target need not rebuild any documentation files; Info files should
normally be included in the distribution, and DVI files should be made
only when explicitly asked for.
@item install
Compile the program and copy the executables, libraries, and so on to
the file names where they should reside for actual use. If there is a
simple test to verify that a program is properly installed, this target
should run that test.
The commands should create all the directories in which files are to be
installed, if they don't already exist. This includes the directories
specified as the values of the variables @code{prefix} and
@code{exec_prefix}, as well as all subdirectories that are needed.
One way to do this is by means of an @code{installdirs} target
as described below.
Use @samp{-} before any command for installing a man page, so that
@code{make} will ignore any errors. This is in case there are systems
that don't have the Unix man page documentation system installed.
The way to install Info files is to copy them into @file{$(infodir)}
with @code{$(INSTALL_DATA)} (@pxref{Command Variables}), and then run
the @code{install-info} program if it is present. @code{install-info}
is a script that edits the Info @file{dir} file to add or update the
menu entry for the given Info file; it will be part of the Texinfo package.
Here is a sample rule to install an Info file:
@smallexample
$(infodir)/foo.info: foo.info
# There may be a newer info file in . than in srcdir.
# Run install-info only if it exists.
# Use `if' instead of just prepending `-' to the
# line so we notice real errors from install-info.
-if test -f foo.info; then d=.; else d=$(srcdir); fi; \
$(INSTALL_DATA) $$d/foo.info $@@; \
if install-info --version >/dev/null 2>&1; then \
install-info --infodir=$(infodir) $$d/foo.info; \
else true; fi
@end smallexample
@item uninstall
Delete all the installed files that the @samp{install} target would
create (but not the noninstalled files such as @samp{make all} would
create).
@comment The gratuitous blank line here is to make the table look better
@comment in the printed Make manual. Please leave it in.
@item clean
Delete all files from the current directory that are normally created by
building the program. Don't delete the files that record the
configuration. Also preserve files that could be made by building, but
normally aren't because the distribution comes with them.
Delete @file{.dvi} files here if they are not part of the distribution.
@item distclean
Delete all files from the current directory that are created by
configuring or building the program. If you have unpacked the source
and built the program without creating any other files, @samp{make
distclean} should leave only the files that were in the distribution.
@item mostlyclean
Like @samp{clean}, but may refrain from deleting a few files that people
normally don't want to recompile. For example, the @samp{mostlyclean}
target for GCC does not delete @file{libgcc.a}, because recompiling it
is rarely necessary and takes a lot of time.
@item realclean
Delete everything from the current directory that can be reconstructed
with this Makefile. This typically includes everything deleted by
@code{distclean}, plus more: C source files produced by Bison, tags tables,
Info files, and so on.
One exception, however: @samp{make realclean} should not delete
@file{configure} even if @file{configure} can be remade using a rule in
the Makefile. More generally, @samp{make realclean} should not delete
anything that needs to exist in order to run @file{configure}
and then begin to build the program.
@item TAGS
Update a tags table for this program.
@item info
Generate any Info files needed. The best way to write the rules is as
follows:
@smallexample
info: foo.info
foo.info: foo.texi chap1.texi chap2.texi
$(MAKEINFO) $(srcdir)/foo.texi
@end smallexample
@noindent
You must define the variable @code{MAKEINFO} in the Make